package _021_10_9

import (
	"sort"
	"strconv"
)

func solve(nums []int) string {
	z := 0
	for z = 0; z < len(nums); z++ {
		if nums[z] != 0 {
			break
		}
	}
	if z == len(nums) {
		return "0"
	}
	// write code here
	_nums := make([]string, 0)
	for i := 0; i < len(nums); i++ {
		_nums = append(_nums, strconv.Itoa(nums[i]))
	}
	sort.Slice(_nums, func(i, j int) bool {
		for k := 0; k < len(_nums[i]) && k < len(_nums[j]); k++ {
			if _nums[i][k] < _nums[j][k] {
				return true
			} else if _nums[i][k] > _nums[j][k] {
				return false
			}
		}
		str1 := _nums[i] + _nums[j]
		str2 := _nums[j] + _nums[i]
		for k := 0; k < len(str1); k++ {
			if str1[k] < str2[k] {
				return true
			} else if str1[k] > str2[k] {
				return false
			}
		}
		if len(str1) < len(str2) {
			return true
		} else {
			return false
		}
	})

	ret := ""
	for i := 0; i < len(_nums); i++ {
		ret += _nums[len(_nums)-1-i]
	}
	return ret
}
